/* 
let login = async (ctx, next) => {
  await axios.get('http://120.77.224.230:9090/user_piling/login', {
    params: { user_name: 'southSZSG', signature: '7c4a8d09ca3762af61e59520943dc26494f8941b' }
  }).then(res => {
  console.log("test -> res", res)
    ctx.response = res.data
  })
} */


const axios = require('axios')

const WECHAT_APPID = 'wx7172826bf2bfaec9'
const WECHAT_APP_SECRET = 'e939ddd496f2ed6c0444096632763cf5'


let login = async (ctx, next) => {
  let code = ctx.query.code
  /* await axios.get('https://api.weixin.qq.com/sns/jscode2session', {
    params: { appid: WECHAT_APPID, secret: WECHAT_APP_SECRET, grant_type: 'authorization_code', js_code: code }
  }).then(res => {
    ctx.set('Content-Type', 'application/json')
    ctx.body  = res.data
  }) */
  try {
    let res = await axios.get('https://api.weixin.qq.com/sns/jscode2session', {
      params: { appid: WECHAT_APPID, secret: WECHAT_APP_SECRET, grant_type: 'authorization_code', js_code: code }
    })
    console.log("login -> res", res.data)
    //  ctx.set('Content-Type', 'application/json')
    ctx.body  = res.data.data
  } catch (err) {
    console.log(err)
  }
}

module.exports = {
  'GET /login': login
}